package com.jwt.demo.utils;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @ClassName: Result
 * @Description: Result
 * @Author zhouzhixin
 * @Date 2021/8/30
 * @Version 1.0
 */
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Result<T> {
    /**
     * 返回代码
     */
    private Integer code;

    /**
     * 返回处理消息
     */
    private String message;

    /**
     * 时间戳
     */
    private long timestamp;

    /**
     * 返回数据对象 data
     */
    private T data;

    public static <T> Result<T> success() {
        return Result.<T>builder().code(200).message("success").timestamp(System.currentTimeMillis()).data(null).build();
    }

    public static <T> Result<T> success(String msg) {
        return Result.<T>builder().code(200).message(msg).timestamp(System.currentTimeMillis()).data(null).build();
    }

    public static <T> Result<T> success(String msg, T data) {
        return Result.<T>builder().code(200).message(msg).timestamp(System.currentTimeMillis()).data(data).build();
    }

    public static <T> Result<T> error() {
        return Result.<T>builder().code(500).message("error").timestamp(System.currentTimeMillis()).data(null).build();
    }

    public static <T> Result<T> error(String msg) {
        return Result.<T>builder().code(500).message(msg).timestamp(System.currentTimeMillis()).data(null).build();
    }

    public static <T> Result<T> error(String msg, T data) {
        return Result.<T>builder().code(500).message("error").timestamp(System.currentTimeMillis()).data(data).build();
    }

}